//
//  Cache.m
//  TaoLeSong
//
//  Created by EmberWei on 2017/07/03.
//  Copyright © 2017年 LimeKing. All rights reserved.
//

#import "Cache.h"

@implementation Cache

+ (Cache *)shared {
    static dispatch_once_t once;
    static id instance;
    dispatch_once(&once, ^{
        instance = [[Cache alloc] init];
    });
    return instance;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initVars];
    }
    return self;
}

-(void)initVars
{
    
}

-(void)setUserId:(NSInteger)userId
{
    [[NSUserDefaults standardUserDefaults] setInteger:userId forKey:@"userId"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

-(NSInteger)userId
{
    return [[NSUserDefaults standardUserDefaults] integerForKey:@"userId"];
}
-(void)setUsername:(NSString *)username
{
    [[NSUserDefaults standardUserDefaults] setObject:username forKey:@"username"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

-(NSString*)username
{
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"username"];
}

-(void)setRegistrationID:(NSString *)registrationID
{
    [[NSUserDefaults standardUserDefaults] setObject:registrationID forKey:@"registrationID"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

-(NSString*)registrationID
{
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"registrationID"];
}

+(void)clear
{
    [Cache shared].userId = 0;
}
@end


